//
//  DSLogInButton.m
//  Competition
//
//  Created by 段帅 on 16/4/12.
//  Copyright © 2016年 newfuture. All rights reserved.
//

#import "DSLogInButton.h"
#import "SCUIToolHeader.h"

#define ColorNormal [UIColor whiteColor]
#define ColorHigh [UIColor colorWithWhite:0.95 alpha:1]


#define Color_title_Normal [UIColor colorWithRed:245/255.0 green:49/255.0 blue:41/255.0 alpha:1.0f]
#define Color_title_High [UIColor colorWithRed:245/255.0 green:49/255.0 blue:41/255.0 alpha:0.2]



@implementation DSLogInButton


-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self createUI];
            }
    
    return self;
    
}
-(void)createUI{
    
   
    
 
        [self setTitle:@"登录" forState:UIControlStateNormal];
     [self setTitle:@"登录中..." forState:UIControlStateSelected];
    
    
    [self setTitleColor:Color_title_Normal forState:UIControlStateNormal];
    [self setTitleColor:Color_title_High forState:UIControlStateHighlighted];
     [self setTitleColor:Color_title_High forState:UIControlStateSelected];
    self.titleLabel.font = NormalFont(30);
    [self setBackgroundImage:[self imageWithColor:ColorNormal] forState:UIControlStateNormal];

    [self setBackgroundImage:[self imageWithColor:ColorHigh] forState:UIControlStateHighlighted];
    [self setBackgroundImage:[self imageWithColor:ColorHigh] forState:UIControlStateSelected];
   
      self.layer.cornerRadius = 2.5;
    self.layer.masksToBounds = YES;
  
    
    self.layer.shadowColor = [UIColor colorWithWhite:0 alpha:0.42].CGColor;
    self.layer.shadowOffset = CGSizeMake(0, 5);
    self.layer.shadowOpacity = 1 ;
    
//    self.clipsToBounds = false ;
//    
    
}

-(void)setIsCanUse:(BOOL )isCanUse{
    
    
    if (isCanUse == NO) {
        self.selected = YES;
        self.userInteractionEnabled = NO;
    }else{
        
        self.selected = NO;
        
        self.userInteractionEnabled = YES;
        
        
    }

    
    
    
}




- (UIImage *)imageWithColor:(UIColor *)color {
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}


- (UIImage *)imageByApplyingAlpha:(CGFloat)alpha  image:(UIImage*)image

{
    
    UIGraphicsBeginImageContextWithOptions(image.size, NO, 0.0f);
    
    
    
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    CGRect area = CGRectMake(0, 0, image.size.width, image.size.height);
    
    
    
    CGContextScaleCTM(ctx, 1, -1);
    
    CGContextTranslateCTM(ctx, 0, -area.size.height);
    
    
    
    CGContextSetBlendMode(ctx, kCGBlendModeMultiply);
    
    
    
    CGContextSetAlpha(ctx, alpha);
    
    
    
    CGContextDrawImage(ctx, area, image.CGImage);
    
    
    
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    
    
    
    UIGraphicsEndImageContext();
    
    
    
    return newImage;
    
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
